Work around access to global resources without calling gtk_init()
authorTristan Van Berkom <tristanvb@openismus.com>
Sun, 24 Mar 2013 08:16:20 +0000 (17:16 +0900)
committerTristan Van Berkom <tristanvb@openismus.com>
Mon, 8 Apr 2013 12:19:27 +0000 (21:19 +0900)
Some utilities such as GIR and gtk-doc, initialize class vtables without
initializing GTK+, with composite templates accessing resources this
causes a hand full of unneeded warnings.

The workaround for now is the use a private function _gtk_ensure_resources()
which is both called while initializing GTK+, and at the beginning of
gtk_widget_class_set_template_from_resource() (the private function
ensures that the resource will only ever be registered GOnce).

gtk/gtkmain.c
gtk/gtkprivate.c
gtk/gtkprivate.h
gtk/tests/Makefile.am

index 18f21718980d506e1dea170b0ec8205633994e27..36a560458493a695b26b5167115e49104307d806 100644 (file)
 #include "gtkmodulesprivate.h"
 #include "gtkprivate.h"
 #include "gtkrecentmanager.h"
-#include "gtkresources.h"
 #include "gtkselectionprivate.h"
 #include "gtksettingsprivate.h"
 #include "gtktooltip.h"
@@ -707,7 +706,7 @@ do_post_parse_initialization (int    *argc,
       g_warning ("Whoever translated default:LTR did so wrongly.\n");
   }
 
-  _gtk_register_resource ();
+  _gtk_ensure_resources ();
 
   _gtk_accel_map_init ();
 
index 70151f9bfe97733efe42def11c23326bb75cbefa..3177d4761d51a251555d097638d6b38e847f3626 100644 (file)
@@ -30,6 +30,7 @@
 #include "gdk/gdk.h"
 
 #include "gtkprivate.h"
+#include "gtkresources.h"
 
 
 #if !defined G_OS_WIN32 && !(defined GDK_WINDOWING_QUARTZ && defined QUARTZ_RELOCATION)
@@ -251,3 +252,18 @@ _gtk_translate_keyboard_accel_state (GdkKeymap       *keymap,
 
   return retval;
 }
+
+static gpointer
+register_resources (gpointer data)
+{
+  _gtk_register_resource ();
+  return NULL;
+}
+
+void
+_gtk_ensure_resources (void)
+{
+  static GOnce register_resources_once = G_ONCE_INIT;
+
+  g_once (&register_resources_once, register_resources, NULL);
+}
index 5b05f5bb47d144a605c3d225c3b6f697b020fdc0..093334f84c0a219553bcbb4b37cf9c1033d52af5 100644 (file)
@@ -59,6 +59,8 @@ gboolean      _gtk_fnmatch                (const char *pattern,
 
 gchar       * _gtk_get_lc_ctype           (void);
 
+void          _gtk_ensure_resources       (void);
+
 gboolean _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
                                            GValue                *return_accu,
                                            const GValue          *handler_return,
index ba24328fa5ba0f96d91e4f91f6b6426e40428f5c..0f2dd781e8360e8a90f22e30e3d5a98df3b89059 100644 (file)
@@ -148,6 +148,7 @@ regression_tests_LDADD               = $(progs_ldadd)
 TEST_PROGS                     += keyhash
 keyhash_SOURCES                         = keyhash.c \
                                   ../gtkkeyhash.c ../gtkkeyhash.h \
+                                  ../gtkresources.c ../gtkresources.h \
                                   ../gtkprivate.c ../gtkprivate.h
 keyhash_LDADD                   = $(progs_ldadd)
 keyhash_CFLAGS                  = -DGTK_COMPILATION \